//
//  HJJCollectViewController.m
//  Pianke
//
//  Created by 黄俊杰 on 16/1/4.
//  Copyright © 2016年 dada. All rights reserved.
//

#import "HJJCollectViewController.h"
#import "HJJRadioDetailCell.h"
#import "Radio.h"
#import "CoreData.h"
#import "HJJPlayerViewController.h"

@interface HJJCollectViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong)UITableView *myTableView;

@property (nonatomic, strong)NSMutableArray *listArray;

@end

@implementation HJJCollectViewController

-(void)viewWillAppear:(BOOL)animated{

    self.listArray = [CoreData selectData:0];
    [self.myTableView reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"我的收藏";
    self.listArray = [NSMutableArray array];
    
    self.myTableView = [[UITableView alloc] init];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    [self.view addSubview:self.myTableView];
    [self.myTableView registerClass:[HJJRadioDetailCell class] forCellReuseIdentifier:@"HJJRadioDetailCell"];
    [self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.left.top.bottom.mas_equalTo(0);
    }];
    
    self.listArray = [CoreData selectData:0];
    [self.myTableView reloadData];
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 70;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.listArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellId = @"HJJRadioDetailCell";
    HJJRadioDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    HJJRadioRootModel *model = [[HJJRadioRootModel alloc] init];
    Radio *radio = [self.listArray objectAtIndex:indexPath.row];
    model.webview_url = radio.webview_url;
    model.coverimg = radio.coverimg;
    model.title = radio.title;
    model.musicUrl = radio.musicUrl;
    model.musicVisit = radio.uname;
    [cell sendModel:model];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [[HJJPlayerViewController sharePlayerViewController] setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
    [HJJPlayerViewController sharePlayerViewController].indexRow = indexPath.row;
    [HJJPlayerViewController sharePlayerViewController].listArray = self.listArray;
    [self presentViewController:[HJJPlayerViewController sharePlayerViewController] animated:1 completion:^{
        
        
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
